package model;

import entity.Account;
import iface.IModel;
import javax.swing.DefaultListModel;

/**
 *
 * @author Noi
 */
public class AccountListModel extends DefaultListModel<Account> implements IModel<Account> {

    private manager.Manager manager;

    public AccountListModel(manager.Manager manager) {
        this.manager = manager;
        this.loadDataToList();
    }

    private void loadDataToList() {
        for (int i = 0; i < this.manager.getAccountManager().size(); i++) {
            if (this.manager.getAccountManager().get(i).isStatus()) {
                this.addElement(this.manager.getAccountManager().get(i));
            }
        }
    }

    @Override
    public void add(Account block) {
        this.manager.getAccountManager().add(block);
        this.addElement(block);
    }

    @Override
    public void replace(int index, Account block) {
        this.manager.getAccountManager().replace(index, block);
        this.set(index, block);
    }

    @Override
    public void remove(Account obj) {
        this.manager.getAccountManager().setVisible(obj, false);
        this.removeElement(obj);
    }

    @Override
    public void refresh() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void add(Object obj) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void replace(int index, Object obj) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void remove(Object obj) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public Object get(int index) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
